﻿using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;

namespace ScormModel
{
    [Serializable()]
    public class Objectives
    {
        private PrimaryObjective _primaryObjective;
        private List<Objective> _listObjective;
        [NonSerialized]
        private XmlNode _objectivesContent;
        [XmlElement("primaryObjective", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public PrimaryObjective PrimaryObjective
        {
            get { return this._primaryObjective; }
            set { this._primaryObjective = value; }
        }

        [XmlElement("objective", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public List<Objective> ListObjective
        {
            get { return this._listObjective; }
            set { this._listObjective = value; }
        }
       
        [XmlIgnoreAttribute]
        public XmlNode ObjectivesContent
        {
            get { return this._objectivesContent; }
            set { this._objectivesContent = value; }
        }
        public void buildObjectives()
        {
            _listObjective = new List<Objective>();
            for (int i = 0; i < _objectivesContent.ChildNodes.Count; i++)
            {
                XmlNode childNodei = _objectivesContent.ChildNodes[i];
                //Lay primaryObjective
                if (childNodei.Name == "imsss:primaryObjective")
                {
                    //if (childNodei.ChildNodes.Count > 0)
                    //{
                        _primaryObjective = new PrimaryObjective();
                        _primaryObjective.PrimaryObjectivesContent = _objectivesContent.ChildNodes[i];
                        _primaryObjective.buildPrimaryObjective();
                    //}
                }
                //Lay objective
                if (((XmlNode)(_objectivesContent.ChildNodes[i])).Name == "imsss:objective")
                {
                    //ObjectiveObject newObjective = new ObjectiveObject(respondingXmlNode.ChildNodes[i]);
                    //objectiveObjectList.Add(newObjective);
                    Objective objective = new Objective();
                    objective.ObjectiveContent = _objectivesContent.ChildNodes[i];
                    objective.buildObjective();
                    _listObjective.Add(objective);
                }
            }
        }
    }
}
